package cn.taichoo.server.service.impl;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.web.domain.AjaxResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import cn.taichoo.server.mapper.PackUpgradeMapper;
import cn.taichoo.server.domain.PackUpgrade;
import cn.taichoo.server.service.IPackUpgradeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.ruoyi.common.security.utils.SecurityUtils;

import javax.annotation.Resource;

/**
 * 手机打包业务-升级配置Service业务层处理
 *
 * @author Wuzh
 * @date 2025-03-17
 */
@Service
@Slf4j
public class PackUpgradeServiceImpl extends ServiceImpl<PackUpgradeMapper, PackUpgrade> implements IPackUpgradeService {

    @Resource
    private PackUpgradeMapper packUpgradeMapper;

    /**
     * 查询手机打包业务-升级配置
     *
     * @param id 手机打包业务-升级配置主键
     * @return 手机打包业务-升级配置
     */
    @Override
    public PackUpgrade selectPackUpgradeById(Long id) {
        return packUpgradeMapper.selectPackUpgradeById(id);
    }

    /**
     * 查询手机打包业务-升级配置列表
     *
     * @param packUpgrade 手机打包业务-升级配置
     * @return 手机打包业务-升级配置
     */
    @Override
    public List<PackUpgrade> selectPackUpgradeList(PackUpgrade packUpgrade) {
        return packUpgradeMapper.selectPackUpgradeList(packUpgrade);
    }

    /**
     * 新增手机打包业务-升级配置
     *
     * @param packUpgrade 手机打包业务-升级配置
     * @return 结果
     */
    @Override
    public AjaxResult insertPackUpgrade(PackUpgrade packUpgrade) {
        packUpgrade.setCreateBy(SecurityUtils.getUserId());
        boolean save = this.save(packUpgrade);
        if (!save) {
            log.error("{}-新增{}失败！", LocalDateTime.now(), packUpgrade.getId());
            throw new RuntimeException("插入失败！" );
        }
        return AjaxResult.success();
    }

    /**
     * 修改手机打包业务-升级配置
     *
     * @param packUpgrade 手机打包业务-升级配置
     * @return 结果
     */
    @Override
    public AjaxResult updatePackUpgradeById(PackUpgrade packUpgrade) {
        boolean b = this.updateById(packUpgrade);
        if (!b) {
            log.error("{}-修改{}失败！", LocalDateTime.now(), packUpgrade.getId());
            throw new RuntimeException("修改失败！" );
        }
        return AjaxResult.success();
    }

    /**
     * 删除手机打包业务-升级配置
     *
     * @param id 手机打包业务-升级配置
     * @return 结果
     */
    @Override
    public AjaxResult deletePackUpgradeById(Long id) {
        boolean update = this.update(new LambdaUpdateWrapper<PackUpgrade>().
                set(PackUpgrade::getDeleted, 1).
                eq(PackUpgrade::getId, id));
        if (!update) {
            log.error("{}-删除{}失败！", LocalDateTime.now(), id);
            throw new RuntimeException("删除失败！" );
        }
        return AjaxResult.success();
    }

}
